package org.example.simpleFactoryModel;

import org.example.simpleFactoryModel.Weapons.Weapon;
import org.example.simpleFactoryModel.Weapons.fighter;
import org.example.simpleFactoryModel.Weapons.machineGun;
import org.example.simpleFactoryModel.Weapons.tank;

/**
 * @auther hewenhui
 * @see <a href="hetp://www.codingmaster.com> java </a>
 */
public class WeaponsFactory {
    public static Object getWeapon(String weaponType){
        if (weaponType == null || weaponType.trim().length() == 0) {
            return null;
        }
        Weapon weapon = null;
        if ("tank".equals(weaponType)) {
            weapon = new tank();
        } else if ("fighter".equals(weaponType)) {
            weapon = new fighter();
        } else if ("machineGun".equals(weaponType)) {
            weapon = new machineGun();
        } else {
            throw new RuntimeException("不支持该武器！");
        }
        return weapon;
    }
}
